<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,  user-scalable=no">

    <title>Glasgow昏迷评分量表（GCS）</title>

    <style>
        /*.table-a table{border:1px solid #000000}*/

        td {
            vertical-align: bottom;
        }

        #table_guage {
            width: 100%;
        }
    </style>


</head>

<body>
<form>
    <div style="font-size: 16px;height: 26px;margin-bottom: 26px;border-bottom: 1px solid #d0d0d0;">
        <label class="print-font16">评定内容</label>
    </div>
    <div class="hide">
        <table border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td align="left" width="80px"><label style="font-size: 13px">陪同者</label></td>
                <td align="left"><input type="text" class="form-control" style="width: 200px;font-size: 13px" id="text_companion"/>
                </td>
            </tr>
        </table>

    </div>

    <!--<div class="view-page hide">-->
    <!--<table border="0" cellspacing="0" cellpadding="0">-->
    <!--<tr>-->
    <!--<td align="left" width="80px"><label style="font-size: 18px">陪同者</label></td>-->
    <!--<td align="left"><label id="span_companion" style="font-weight:normal;font-size: 18px"></label></td>-->
    <!--</tr>-->
    <!--</table>-->
    <!--</div>-->

    <!--<table id="table_total" class="view-page table table-bordered hide" style="margin-top: 20px;font-size: 13px" border="1"-->
    <!--cellspacing="0" cellpadding="0">-->
    <!--<tr>-->
    <!--<td width="40%" align="center"><label>总分</label></td>-->

    <!--<td width="60%" align="center"><span class="span-total-score"></span></td>-->
    <!--</tr>-->

    <!--</table>-->

    <!--<div style="margin-bottom: 30px;font-size: 20px">-->
    <!--<label>评定内容</label>-->
    <!--</div>-->


    <div class="table-a" style="margin-top: 40px">
        <table id="table_guage" border="0" cellspacing="0" cellpadding="0">
        </table>
    </div>
    <div style="font-size: 16px;height: 26px;margin-top:26px;margin-bottom: 26px;border-bottom: 1px solid #d0d0d0;">
        <label class="print-font16">评定结果</label>
    </div>
    <table id="table_total_edit" class="table table-bordered" style="margin-top: 20px;font-size: 13px" border="1"
           cellspacing="0"
           cellpadding="0">
        <tr>

            <td width="40%" align="center"><span>总分</span></td>


            <td width="60%" align="center"><span class="span-total-score"></span></td>
        </tr>

    </table>


    <div class="edit-page hide" style="margin-top: 20px">
        <div class="col-sm-8 col-sm-offset-4">
            <button class="btn btn-white col-sm-3" type="button" onclick="myReset()">重置</button>
            <button class="btn btn-primary col-sm-3 col-sm-offset-1" onclick="submitGaugeResult()" type="button">提交
            </button>
        </div>
    </div>
</form>
</body>

<script>

    var totalScore = 0;

    var spanTotalScore = $(".span-total-score");

    //    var tableTotalEdit = $("#table_total_edit");
    //    var tableTotal = $("#table_total");

    var editPage = $(".edit-page");
    var viewPage = $(".view-page");

    var textCompanion = $("#text_companion");
    var spanCompanion = $("#span_companion");

    var gauge_groups = [''];

    var gauge_options = [
        ['睁眼（E）', '言语反映（V）', '非偏瘫侧运动反映（M）']
    ];

    builderQuestion();


    function builderQuestion() {

        var radioType2List = '睁眼（E）&';
        var radioType3List = '言语反映（V）&';
        var radioType4List = '非偏瘫侧运动反映（M）&';

        var index = 1;

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {

                if (j == 0 && gauge_groups[i] != '') {
                    //添加组标题
                    var groupTr =
                        "<tr><td  height='10px'></td></tr>" +
                        "<tr><td align='left' ><label>" + gauge_groups[i] + "</label></td></tr>";
                    $("#table_guage").append(groupTr);
                }

                var radio;

                if (radioType2List.indexOf(gauge_options[i][j].trim() + '&') != -1) {
                    radio = '<table width="100%" border="0" cellspacing="0" cellpadding="0">' +
                        '<tr>' +
                        '<td align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="4" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>自己睁眼</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="3" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>呼叫时睁眼</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="2" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>疼痛刺激时睁眼</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="1" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>任何刺激不睁眼</label></td>' +
                        '</tr></table>';
                } else if (radioType3List.indexOf(gauge_options[i][j].trim() + '&') != -1) {
                    radio = '<table width="100%"  border="0" cellspacing="0" cellpadding="0">' +
                        '<tr>' +
                        '<td align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="5" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>正常</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="4" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>有错语</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="3" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>词不达意</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="2" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>不能理解</label></td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="1" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>无言语</label></td>' +
                        '<td  width="25%" align="left">' +
                        '<td  width="25%" align="left">' +
                        '<td  width="25%" align="left">' +
                        '</tr>' +
                        '</table>';
                } else if (radioType4List.indexOf(gauge_options[i][j].trim() + '&') != -1) {
                    radio = '<table width="100%"  border="0" cellspacing="0" cellpadding="0">' +
                        '<tr>' +
                        '<td align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="6" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>正常（服从命令）</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="5" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>疼痛时能拨开医生的手</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="4" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>疼痛时逃避反应</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="3" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>疼痛时呈屈曲状态</label></td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="2" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>疼痛时呈伸展状态</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="1" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>无运动</label></td>' +
                        '<td  width="25%" align="left">' +
                        '<td  width="25%" align="left">' +
                        '</tr></table>';
                }

                var selectTr = "<tr>" +
                    "<td align='left' style='font-size:13px' id='td_" + i + "_" + j + "'>" + (index++) + " ．" + gauge_options[i][j].trim() + "</td>" +
                    "</tr>" +
                    "<tr><td style='padding-left: 5vw' id='td_select_" + i + "_" + j + "'>" +
                    "</td></tr>" + "<tr><td height='6.5px' style='border-bottom:1px dashed #d0d0d0;'></td></tr><tr><td height='6.5px'></td></tr>";
//                        "<tr><td height='15px'><hr style='height:1px;border:none;border-top:1px dashed #d0d0d0;'/></td></tr>";

                $("#table_guage").append(selectTr);
                $("#td_select_" + i + "_" + j).append(radio);
            }
        }

//        if (editable == false) {
//            $(".question-radio").attr('disabled', 'disabled');
//        }
    }

    function changeSelect() {

        totalScore = 0;

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
//                var value=$("#select_" + i + "_" + j).val();
                var value = $("input[name='radio_" + i + "_" + j + "']:checked").val();
                if (typeof(value) == "undefined") {
                    value = 0;
                }
                totalScore += parseInt(value);
            }
        }
        spanTotalScore.text(totalScore);


    }

    //    function submit() {
    //        changeSelect();
    //        var gauge = {};
    //
    //        gauge.total_score = totalScore;
    //
    //        var questions = [];
    //
    //        var index = 0;
    //
    //        for (var i = 0; i < gauge_groups.length; i++) {
    //            for (var j = 0; j < gauge_options[i].length; j++) {
    //                var questionKey = $("#td_" + i + "_" + j).html();
    //                questionKey = questionKey.split("．")[1].trim();
    //
    //                var result = $("input[name='radio_" + i + "_" + j + "']:checked").val();
    //                if (typeof(result) == "undefined") {
    //                    result = 0;
    //                }
    //                var question = {};
    //                question.key = questionKey;
    //                question.value = result;
    //                questions[index++] = question;
    //            }
    //        }
    //
    //        gauge.questions = questions;
    //
    //        gauge.companion=textCompanion.val();
    //
    //        debugAlert(gauge);
    //
    //        mandy_post_gauge_record_result(gaugeRecordId, JSON.stringify(gauge), function (data) {
    //            debugAlert(data);
    //            utils.msgSuccess("提交成功");
    //        });
    //    }


    function setEditable(edit) {
        editPage.removeClass('hide');
        if (edit == true || edit == 'true') {
//            editPage.removeClass('hide');
//            viewPage.addClass('hide');
        } else {
//            mandy_get_gauge_record(gaugeRecordId,prcpItemId, function (data) {
//                debugAlert(data.result);
//                var result = eval('(' + data.result + ')');
//
//                for (var i = 0; i < gauge_groups.length; i++) {
//                    for (var j = 0; j < gauge_options[i].length; j++) {
//                        var questions = result.questions;
//                        for (var k = 0; k < questions.length; k++) {
//                            if (questions[k].key.trim() == gauge_options[i][j].trim()) {
//                                $("input[name='radio_" + i + "_" + j + "']:eq(" + questions[k].value + ")").attr("checked", 'checked');
//                            }
//                        }
//                    }
//                }
//
//                spanCompanion.text(result.companion);
//
//                spanTotalScore.text(result.total_score);
//
//                if (result.total_score < 20) {
//                    spanAdlSpan.text("极严重功能缺陷");
//                } else if (result.total_score < 45) {
//                    spanAdlSpan.text("严重功能缺陷");
//                }
//                else if (result.total_score < 70) {
//                    spanAdlSpan.text("中度功能缺陷");
//                }
//                else if (result.total_score < 95) {
//                    spanAdlSpan.text("轻度功能缺陷");
//                }
//                else if (result.total_score < 100) {
//                    spanAdlSpan.text("ADL自理");
//                }
//            });
            textCompanion.attr("disabled", true);
//            viewPage.removeClass('hide');
            editPage.addClass('hide');
            $(".question-radio").attr('disabled', 'disabled');
        }

    }

    function setGaugeResult(result) {
        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
                var questions = result.questions;
                for (var k = 0; k < questions.length; k++) {
                    if (questions[k].key.trim() == gauge_options[i][j].trim()) {
                        $("input[name='radio_" + i + "_" + j + "'][value=" + questions[k].value + "]").attr("checked", 'checked');
                    }
                }
            }
        }

        if (result.companion == null || result.companion == '') {
//            spanCompanion.text("无");
        } else {
//            spanCompanion.text(result.companion);
            textCompanion.val(result.companion);
        }

        spanTotalScore.text(result.total_score);

        if (result.total_score < 20) {
            spanAdlSpan.text("极严重功能缺陷");
        } else if (result.total_score < 45) {
            spanAdlSpan.text("严重功能缺陷");
        }
        else if (result.total_score < 70) {
            spanAdlSpan.text("中度功能缺陷");
        }
        else if (result.total_score < 95) {
            spanAdlSpan.text("轻度功能缺陷");
        }
        else if (result.total_score < 100) {
            spanAdlSpan.text("ADL自理");
        }
    }

    function getGaugeResult() {
        changeSelect();
        var gauge = {};

        gauge.total_score = totalScore;

        var questions = [];

        var index = 0;

//        if(textCompanion.val().trim()==null||textCompanion.val().trim()==''){
//            utils.msgError("请填写陪同者!");
//            return;
//        }

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
                var questionKey = $("#td_" + i + "_" + j).html();
                questionKey = questionKey.split("．")[1].trim();

                var result = $("input[name='radio_" + i + "_" + j + "']:checked").val();
                if (typeof(result) == "undefined") {
//                    result = 0;
                    var noCheckedIndex = i * gauge_groups.length + j + 1;
                    utils.msgError("第" + (index + 1) + "个选项还未评估!");
                    $("input[name='radio_" + i + "_" + j + "']").focus();
                    return;
                }
                var question = {};
                question.key = questionKey;
                question.value = result;
                questions[index++] = question;
            }
        }

        gauge.questions = questions;

        gauge.companion = textCompanion.val().trim();
//        spanCompanion.text(gauge.companion);
        textCompanion.val(gauge.companion);
        debugAlert(gauge);
        return gauge;
    }

    function getCount() {
        spanTotalScore.text(null);
    }

</script>

</html>
